package cn.emall.controller;

import cn.emall.content.service.ContentCatService;
import cn.emall.pojo.EasyUITreeNode;
import cn.emall.utils.EmallResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 内容分类管理Controller
 */
@Controller
public class ContentCatController {

    @Autowired
    private ContentCatService contentCatService;

    @RequestMapping(value = "/content/category/list")
    @ResponseBody
    public List<EasyUITreeNode> getTreeNode(@RequestParam(name = "id",defaultValue = "0") Long parentId){
        List<EasyUITreeNode> treeNodes = contentCatService.getTreeNode(parentId);
        return treeNodes;
    }

    @RequestMapping(value="/content/category/create",method = RequestMethod.POST)
    @ResponseBody
    public EmallResult addTree(Long parentId,String name){
        EmallResult emallResult = contentCatService.addTree(parentId,name);
        return emallResult;
    }
}
